package bomberman.entity;

import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;

import bomberman.BombermanGameLevel;


import gameframework.base.Drawable;
import gameframework.base.DrawableImage;
import gameframework.base.Overlappable;
import gameframework.game.GameEntity;
import gameframework.game.GameMovable;
import gameframework.game.GameUniverse;

public class Fire extends GameMovable implements Drawable, GameEntity, Overlappable {

	public static final int FIRE_SPRITE_SIZE = 12;
	public static final int TIME_TO_BURN = 4;
	public static final int NORTH = 5;
	public static final int WEST = 6;
	public static final int EAST = 6;
	public static final int SOUTH = 5;
	public static final int END_NORTH = 1;
	public static final int END_WEST = 3;
	public static final int END_SOUTH = 2;
	public static final int END_EAST = 4;
	public static final int MIDDLE = 0;
	
	private DrawableImage image;
	private Point position;
	protected int fireTimer = TIME_TO_BURN;
	private int fireDir;
	private int spriteNumber = 0;
	
	public Fire(Canvas defaultCanvas, Point pos, GameUniverse gu, int direction){
		image = new DrawableImage("images/Fire.png", defaultCanvas);
		fireDir = direction;	
		position = pos;
	}
	
	@Override
	public void draw(Graphics g) {
		int spriteType = fireDir;

		g.drawImage(image.getImage(), (int) getPosition().getX(),
				(int) getPosition().getY(), (int)getPosition().getX()+ BombermanGameLevel.SPRITE_SIZE,
				(int) getPosition().getY() + BombermanGameLevel.SPRITE_SIZE, spriteNumber * FIRE_SPRITE_SIZE,
				spriteType * FIRE_SPRITE_SIZE, (spriteNumber + 1) * FIRE_SPRITE_SIZE,
				(spriteType + 1) * FIRE_SPRITE_SIZE,null);	
		}

	@Override
	public Point getPosition() {
		return position;
	}

	@Override
	public Rectangle getBoundingBox() {
		return (new Rectangle((int) position.getX(), (int) position.getY(),
				BombermanGameLevel.SPRITE_SIZE, BombermanGameLevel.SPRITE_SIZE));
	}
	
	public void oneStepMoveHandler(){
		spriteNumber++;
		if(fireTimer-- == 0)
			BombermanGameLevel.medUniverse.getUniverse().removeGameEntity(this);
	}

}
